package com.martin.lib_base.ui.screen

import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.shadow
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import coil.compose.AsyncImage
import com.martin.lib_base.R
import com.martin.lib_base.ui.theme.ColorTextNormal
import com.martin.lib_base.ui.theme.Typography
import dev.DevUtils

/**
 * @author：孟凡华
 * @date：2023/7/5
 * @desc：
 */

@Composable
fun TitleBar(
    title: String,
    onBackClick: () -> Unit,
    bgColor: Color = Color.White,
    titleColor: Color = ColorTextNormal,
    backImageId: Int = R.drawable.img_back,
    backImage: @Composable () -> Unit = {
        Image(painter = painterResource(id = backImageId),
            contentDescription = "back",
            modifier = Modifier
                .padding(start = 5.dp)
                .height(44.dp)
                .width(44.dp)
                .clickable {
                    onBackClick()
                }
                .padding(11.dp)
        )
    },
    right: @Composable () -> Unit = {},
) {
    Box(
        modifier = Modifier
            .fillMaxWidth()
            .height(44.dp)
            .background(color = bgColor)
    ) {
        backImage.invoke()
        Text(
            text = title,
            style = Typography.titleSmall,
            color = titleColor,
            modifier = Modifier.align(Alignment.Center)
        )
        Box(
            modifier = Modifier
                .align(Alignment.CenterEnd)
                .padding(end = 5.dp)
        ) {
            right()
        }
    }
}

@Preview
@Composable
fun PreviewTitleBar() {
    Box(
        modifier = Modifier
            .fillMaxSize()
            .background(color = Color.White)
    ) {
        TitleBar(title = "标题", onBackClick = {})
    }
}